import java.util.Arrays;
import java.util.Scanner;

public class XingYunChouJiang {

	public static void main(String[] args) {
		// 综合练习：幸运抽奖
		String answer = "N";
		String userName = "null";
		int userPass = 0;
		int userNum = 0;
		boolean user = false;
		boolean login = false;
		do {
			System.out.println("*****欢迎进入大富翁系统*****");
			System.out.println("1、注册\n2、登录\n3、抽奖");
			System.out.println("*************************");
			Scanner input = new Scanner(System.in);
			System.out.print("请选择菜单：");
			int num = input.nextInt();
			if (num == 1) {// 注册
				System.out.println("[大富翁系统>注册]");
				System.out.println("请填写个人信息：");
				System.out.print("用户名：");
				userName = input.next();
				System.out.print("密码：");
				userPass = input.nextInt();
				userNum = (int) (Math.random() * 9000 + 1000);

				System.out.println("注册成功，请记好您的会员卡号：");
				System.out.println("用户名\t密码\t会员卡号");
				System.out.println(userName + "\t" + userPass + "\t" + userNum);
				user = true;

			} else if (num == 2) {// 登录
				System.out.println("[大富翁系统>登录]");
				if (user) {
					for (int i = 2; i >= 0; i--) {
						System.out.print("请输入用户名：");
						String inputName = input.next();
						System.out.print("请输入密码：");
						int inputPass = input.nextInt();

						if (inputName.equals(userName) && (inputPass == userPass)) {
							System.out.println("登录成功！" + userName + "欢迎您！您的会员卡号是：" + userNum);
							login = true;
							break;
						} else if (i > 0) {
							System.out.println("您的信息输入有误！您还有" + i + "次输入机会！");
						} else if (i == 0) {
							System.out.println("您的信息3次输入有误！系统退出！");
							break;
						}
					}
				} else {
					System.out.println("请您先注册！");
				}
			} else if (num == 3) {// 抽奖
				System.out.println("[大富翁系统>抽奖]");
				if (login) {
					System.out.print("请输入您的会员卡号：");
					int inputNum = input.nextInt();
					if (inputNum == userNum) {
						int[] luckyNum = new int[4];
						for (int i = 0; i < luckyNum.length; i++) {
							luckyNum[i] = (int) (Math.random() * 9000 + 1000);
						}
						System.out.print("本期的幸运数字是：");
						System.out.println(Arrays.toString(luckyNum));
						int lucky = 0;
						for (int i = 0; i < luckyNum.length; i++) {
							if (userNum == luckyNum[i]) {
								System.out.println("恭喜您是本期的幸运儿！");
								break;
							}
							lucky++;
						}
						if (lucky == 4) {
							System.out.println("很抱歉您不是本期的幸运会员！");
							answer = "N";
							break;
						}
					} else {
						System.out.println("会员卡号输入错误，您的会员卡号是：" + userNum);
					}
				} else {
					System.out.println("请您先登录！");
				}
			} else {
				System.out.println("您的输入有误！");
			}
			System.out.print("-----------------\n继续吗？(y/n)");
			answer = input.next();
		} while (answer.equals("y") || answer.equals("Y"));
		if (answer.equals("n") || answer.equals("N")) {
			System.out.println("系统退出，谢谢使用！");
		} else {
			System.out.println("您的输入有误！系统退出！");
		}

	}

}
